using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class GamePlayPanel : MonoBehaviour
{
   [Header("广播事件")]
   public ObjectEventSO playerTurnEndEvent;
   
   private VisualElement rootElement;
   private Label energyAmountLabel,drawAmountLabel,discardAmountLabel,turanLabel;

   private Button endTurnButton;
   

   private void OnEnable()
   {
      rootElement = GetComponent<UIDocument>().rootVisualElement;
      
      energyAmountLabel = rootElement.Q<Label>("EnergyAmount");
      drawAmountLabel = rootElement.Q<Label>("DrawAmount");
      discardAmountLabel = rootElement.Q<Label>("DiscardAmount");
      turanLabel = rootElement.Q<Label>("TurnLabel");
      
      endTurnButton = rootElement.Q<Button>("EndTurn");
      endTurnButton.clicked += OnEndTurnButtonClicked;
      
      drawAmountLabel.text = "0";
      discardAmountLabel.text = "0";
      energyAmountLabel.text = "0";
      turanLabel.text = "游戏开始";
   }

   private void OnEndTurnButtonClicked()
   {
      playerTurnEndEvent.RaisEvent(null,this);
   }

   public void UpdateDrawDeckAmount(int amount)
   {
      drawAmountLabel.text = amount.ToString();
   }
   public void UpdateDiscardDeckAmount(int amount)
   {
      discardAmountLabel.text = amount.ToString();
   }

   public void UpdateEnergyAmount(int amount)
   {
      energyAmountLabel.text = amount.ToString();
   }

   public void OnEnemyTurnBegin()
   {
      endTurnButton.SetEnabled(false);
      turanLabel.text = "敌人回合";
      turanLabel.style.color = new StyleColor(Color.red);
   }

   public void OnPlayerTurnBegin()
   {
      endTurnButton.SetEnabled(true);
      turanLabel.text = "玩家回合";
      turanLabel.style.color = new StyleColor(Color.white);
   }

   public void OnCharacterDead()
   {
      endTurnButton.SetEnabled(false);
   }
   

}
